/* 
Code generates sample descriptive tables (Table 1 and Table A1)
*/

* LOAD UP BASELINE CHARACTERISTICS
*-------------------------------------------------------------------------------
 
use "$data/initial_data/sample_chars",replace

* label vars 
*-------------------------------------------------------------------------------

lab var age "Age in years"
lab var canread "Can read complete sentence (in Hindi)*"
lab var age_marriage "Own age at marriage in years*"
lab var num_sons "Number of sons*"
lab var num_daughters "Number of daughters*"
lab var dirtfloor "House has dirt floor*"
lab var scst "Scheduled caste or scheduled tribe*"
lab var obcebc "Other Backward Caste or Economically Backward Class*"
lab var religion "Hindu*"
lab var somesay_when "At least some say over when child gets married"
lab var somesay_who "At least some say over to whom child gets married"
lab var somesay_school "At least some say over when child leaves school"
lab var anywork "Has done any work (inc. on family farm) in last year"
lab var workforcash "Has worked for cash in last year"
lab var married_child "Has child (male or female) who is married"
lab var yearsschool "Years of school*"
lab var ownasset "Owns asset that can dispose of at will"
lab var market "Can go to market unaccompanied*"



* merge in whether in ex-post or ex-ante sample
*-------------------------------------------------------------------------------

preserve
use "$data/initial_data/exante_data.dta"
keep carer_id
duplicates drop carer_id, force
tempfile temp 
save `temp'

use "$data/initial_data/expost_data.dta", clear

keep carer_id
duplicates drop carer_id, force
destring _all, replace
tempfile temp2 
save `temp2'
restore

merge 1:1 carer_id using `temp'
gen exante=(_merge==3)
drop _merge

merge 1:1 carer_id using `temp2'
gen expost=(_merge==3)
drop _merge


* merge in indicator for who was in followup
*-------------------------------------------------------------------------------
preserve
use  "$data/created_data/Observed Trajectories (5-year FU) -- cleaned.dta", clear
gen in_followup=married13~=.
collapse (mean) in_followup, by(carer_id)
drop if carer_id==.
replace in_followup=1 if in_followup>0 & in_followup<.
tab in_followup
tempfile in_followup
save `in_followup'
restore

merge 1:1 carer_id using `in_followup'
drop _merge


* Table 1: Sample descriptives
*-------------------------------------------------------------------------------

global vars "summarize age age_marriage yearsschool canread num_sons num_daughters ownasset  market somesay* anywork workforcash married_child dirtfloor scst obcebc religion"

gen exp_sample=(expost==1 |  exante==1)
tab exp_sample if in_followup==1

estimates clear
eststo clear
eststo: estpost $vars  if expost==1 |  exante==1
eststo: estpost $vars if in_followup==1 

esttab *,  cells("mean(fmt(a3) label(Mean)) sd(fmt(a3) par label(Standard Deviation))") replace label noobs  mtitle("Exp. Sample" "in followup")   eqlabels("dd" "" "") scalars(N N ) wide

esttab *  using "$output/descriptives.tex", booktabs  cells("mean(fmt(a3) label(Mean)) sd(fmt(a3) par label(Standard Deviation))") replace label noobs  mtitle("Exp. Sample" "in followup")   eqlabels("dd" "" "") scalars(N N ) wide


* Table A1:  Balance by whether respondent was assigned to ex-post vs. ex-ante survey instrument
*-------------------------------------------------------------------------------
eststo clear
eststo: estpost $vars if expost==1
eststo: estpost $vars if exante==1
esttab *,  cells("mean(fmt(a3) label(Mean))" "sd(fmt(a3) par label(Standard Deviation))") replace label noobs  mtitle("expost" "exante")   eqlabels("dd" "" "") scalars(N N )

esttab * using "$output/descriptives_by_exp.tex",  cells("mean(fmt(a3) label(Mean))" "sd(fmt(a3) par label(Standard Deviation))") replace label noobs  mtitle("expost" "exante")   eqlabels("dd" "" "") scalars(N N )
